/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.ui.util;

import java.io.File;

import javax.swing.filechooser.FileFilter;

import who.tmap.dao.FileExtensions;

/**
 * @author stl
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class FileChooserFilter extends FileFilter
							   implements FileExtensions {
		
	public static final File TMAPS_DIR =new File( "tmaps" );	
	public static final File MAPS_DIR =new File( "maps" );
	public static final File DATA_DIR =new File( "data" ); 
	public static final File CDS_DIR =new File( "cds" );
	public static final File ANNOTATIONS_DIR =new File( "anns" );	
		
	private String ext, desc;
			
	public FileChooserFilter( String ext ) {
		super();
		
		this.ext =ext;
				
		if ( MULTI_LAYER_THEMATIC_MAP_EXT.equals( ext ) ) {
			desc ="Multi-layer thematic map files (*" + ext + ")";		
		} else if ( THEMATIC_MAP_EXT.equals( ext ) ) {
			desc ="Thematic map files (*" + ext + ")";
		} else if ( THEMATIC_MAP_LINKED_EXT.equals( ext ) ) {
			desc ="Thematic map linked files (*" + ext + ")";			
		} else if ( BASE_MAP_EXT.equals( ext ) ) {
			desc ="Base map files (*" + ext + ")";
		} else if ( SHAPE_FILE_EXT.equals( ext ) ) {
			desc ="Shape files (*" + ext + ")";			
		} else if ( DATA_EXT.equals( ext ) ) {
			desc ="Data files (*" + ext + ")";
		} else if ( SHAPE_DBF_FILE_EXT.equals( ext ) ) {
			desc ="dBase files (*" + ext + ")";			
		} else if ( CARTOGRAPHIC_DISPLAY_EXT.equals( ext ) ) {
			desc ="Cartographic display files (*" + ext + ")";
		} else if ( ANNOTATIONS_EXT.equals( ext ) ) {
			desc ="Annotations files (*" + ext + ")";
		} else if ( CSV_EXT.equals( ext ) ) {
			desc ="Flat files (*" + ext + ")";	
		} else if ( EXCEL_EXT.equals( ext ) ) {
			desc ="Excel files (*" + ext + ")";	
		} else if ( GIF_EXT.equals( ext ) ) {
			desc ="GIF files (*" + ext + ")";
		} else if ( JPG_EXT.equals( ext ) ) {
			desc ="JPEG files (*" + ext + ")";	
		} else if ( PNG_EXT.equals( ext ) ) {
			desc ="PNG files (*" + ext + ")";				
		} else if ( DBF_EXT.equals( ext ) ) {
			desc ="dBase files (*" + ext + ")";	
		} else if ( MDB_EXT.equals( ext ) ) {
			desc ="MS Access database (*" + ext + ")";				
		} else if ( PDF_EXT.equals( ext ) ) {
			desc ="Acrobat document (*" + ext + ")";				
		} else {
			desc ="";
		}
	}			
			
	public FileChooserFilter( String ext, String desc ) {
		super();
				
		this.ext =ext;
		this.desc =desc;
	}
			
	public boolean accept(File file) {
		String filename = file.getName();
	
		return file.isDirectory() || filename.toLowerCase().endsWith( ext );
	}
			
	public String getDescription() {
		return desc;
	}
	
	/**
	 * Remove the leading dot to get the proper extension
	 * @return
	 */
	public String getExtension() {
		return ext.substring(1);
	}

}
